﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace LX.MVC.Open.CustomExtend
{
    public class BrowserRoute : RouteBase
    {
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            if (!httpContext.Request.UserAgent.Contains("Chrome/75.0.3770.100"))
            {
                RouteData data = new RouteData(this, new RouteHandler());
                //data.Values.Add("controller", "Home");
                //data.Values.Add("action", "Refuse");
                return data;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 支持webform的route拓展
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            return null;
        }
    }

    public class RouteHandler : IRouteHandler
    {
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            return new HttpHandler();
        }
    }
    public class HttpHandler : IHttpHandler
    {
        bool IHttpHandler.IsReusable => true;

        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            context.Response.Write("This is hjw Framework!");
            string path = context.Server.MapPath("Web.config");
            context.Response.Write(File.ReadAllText(path));
            context.Response.End();
        }
    }

}